package org.metasketch.ham.diagrams;

import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Polyline;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeType;

import org.metasketch.demo.model.OrganizationalUnit;
import org.metasketch.diagram.javafx.graphics.BaseGraphic;
import org.metasketch.diagram.javafx.graphics.CustomLabel;
import org.metasketch.graphics.GraphicContainer;

public class HumanActivityGroupNode extends BaseGraphic {

	// Rectangle rect;//

	// Polygon polygon1 = new Polygon();

	Polyline left = new Polyline();
	Polyline right = new Polyline();

	// CustomLabel label = new CustomLabel("Untitled");

	Color lineColor = Color.BLACK;
	Rectangle rect;

	public HumanActivityGroupNode() {
		super(new GraphicContainer(0, 0, 400, 200));

	}

	@Override
	protected void continueSetup() {

		setupGraphic(graphicNode.getX(), graphicNode.getY(),
				graphicNode.getWidth(), graphicNode.getHeight());

	}

	private void setupGraphic(int x, int y, int width, int height) {

		this.width = width;
		this.height = height;

		setX(x);
		setY(y);

		left.setStroke(lineColor);
		left.setStrokeWidth(2);

		right.setStroke(lineColor);
		right.setStrokeWidth(2);

		rect = new Rectangle(1, 1, width, height);
		rect.setStroke(Color.TRANSPARENT);
		rect.setFill(Color.TRANSPARENT);

		buildShapes();

		getChildren().addAll(rect, left, right);
	}

	private void buildShapes() {

		rect.setWidth(width);
		rect.setHeight(height);

		left.getPoints().clear();
		right.getPoints().clear();

		double indentation = 10d;
		double dualIndentation = indentation * 2;

		double middle = height * 0.5;
		left.getPoints().addAll(
				new Double[] { dualIndentation, 0d, indentation, indentation,
						indentation, middle - indentation, 0d, middle,
						indentation, middle + indentation, indentation,
						(double) height - indentation, dualIndentation,
						(double) height });

		right.getPoints().addAll(
				new Double[] { (double) width - dualIndentation, 0d,
						(double) width - indentation, indentation,
						(double) width - indentation, middle - indentation,
						(double) width, middle, (double) width - indentation,
						middle + indentation, (double) width - indentation,
						(double) height - indentation,
						(double) width - dualIndentation, (double) height });

	}

	@Override
	protected void resizeGraphic() {
		// rect.setWidth(width);
		// rect.setHeight(height);
		//
		// label.resize();
		buildShapes();

	}

	@Override
	protected void refreshModelGraphic() {
		// OrganizationalUnit role = (OrganizationalUnit) semantic;

		// label.setText(role.getName());

		// label.refreshModelGraphic();
		// identifierLabel.refreshModelGraphic();

	}

}
